
import 'package:share_fit/app/models/base_model.dart';
import 'package:share_fit/app/tools/log_utils.dart';
import 'package:share_fit/app/ute/uteped_const.dart';

class DeviceInfo extends BaseModel {

  String name = "";
  String model = "";
  String battery = "";
  bool checked = false;
  int state = -1;

  String deviceVersion = "";//硬件版本号
  String systemVersion = "";//软件版本号
  String firmware = "";
  String firmwareVersion = "";
  String versionName = "";

  @override
  bool from(Map<dynamic, dynamic> map) {
    try {
      name = map[UTEPedConst.keyName];
      address = map[UTEPedConst.keyAddress];
      model = map[UTEPedConst.keyModel];
      battery = map[UTEPedConst.keyBattery].toString();
      deviceVersion = map["deviceVersion"];
      systemVersion = map["systemVersion"];
      if (map.containsKey(UTEPedConst.keyFirmware)) {
        firmware = map[UTEPedConst.keyFirmware];
        versionName = systemVersion.replaceAll(firmware, "");
      }
      if (map.containsKey(UTEPedConst.keyFirmwareVersion)) {
        firmwareVersion = map[UTEPedConst.keyFirmwareVersion];
      }

    } catch(e, stack) {
      logger.d(e);
    }

    return true;
  }

  @override
  // TODO: implement props
  List<Object?> get props => [];

  void reset() {
    name = "";
    model = "";
    battery = "";
    checked = false;
    state = -1;

    deviceVersion = "";//硬件版本号
    systemVersion = "";//软件版本号
    firmware = "";
    firmwareVersion = "";
    versionName = "";
  }
}